﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace Vmago.Models
{
    public class RepositoryShopSearch:IShopSearch
    {
        #region IShopSearch Members

        private ShopSearchDataContext ds;

        public RepositoryShopSearch()
        {
            ds = new ShopSearchDataContext();
        }

        public List<SearchKey> doShopSearch(string searchString , int cityID, int categoryID)
        {
            List<SearchKey> c = null;
            try
            {
                c = ds.doShopSearch(searchString,cityID, categoryID).ToList();
            }
            catch (Exception ex)
            {
                ds.Dispose();
                Console.WriteLine(ex.ToString());
                throw;
            }
            return c;
        }

        public List<SearchResult> getShopSearchResult(int searchID, int resultCount, int perPage, int pageNumber)
        {
            List<SearchResult> c = null;
            try
            {
                c = ds.getShopSearch(searchID,resultCount, perPage,pageNumber).ToList();
            }
            catch (Exception ex)
            {
                ds.Dispose();
                Console.WriteLine(ex.ToString());
                throw;
            }
            return c;
        }

        public IEnumerable<SearchRanking> getShopSearchRanking(int top)
        {
            IEnumerable<SearchRanking> c = null;
            try
            {
                c = from p in ds.SearchRankings
                    where p.ranking <= top 
                    select p;
            }
            catch (Exception ex)
            {
                ds.Dispose();
                Console.WriteLine(ex.ToString());
                throw;
            }
            return c;

        }

        #endregion
    }
}
